package com.zhiqiang.gameserver.netty;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.timeout.IdleStateHandler;

/**
 * @author YAO
 */
public class NettyGameInitializer extends ChannelInitializer<SocketChannel> {
    @Override
    protected void initChannel(SocketChannel ch) throws Exception {
        ChannelPipeline channelPipeline = ch.pipeline();
        channelPipeline.addLast(new NettyGameServerDecoder());
        channelPipeline.addLast(new NettyGameServerEncoder());
        channelPipeline.addLast(new IdleStateHandler(31,0,0));
        channelPipeline.addLast(new NettyGameServerHandler());

    }

    @Override
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
        cause.printStackTrace();
        ctx.close();
    }
}
